<template>
  <div class="order-confirm">
    <div class="container">
      <h1 class="page-title">订单确认</h1>

      <el-card class="order-card">
        <div class="movie-info">
          <img :src="movie.poster" :alt="movie.title" class="movie-poster">
          <div class="info-content">
            <h2>{{ movie.title }}</h2>
            <p>场次：{{ screening.time }}</p>
            <p>影厅：{{ screening.hall }}</p>
            <p>座位：
              <el-tag v-for="seat in selectedSeats" :key="seat" size="small" class="seat-tag">
                {{ seat }}
              </el-tag>
            </p>
          </div>
        </div>

        <el-divider></el-divider>

        <div class="price-info">
          <div class="price-item">
            <span>票价</span>
            <span>¥{{ screening.price }} × {{ selectedSeats.length }}</span>
          </div>
          <div class="price-item">
            <span>服务费</span>
            <span>¥{{ serviceFee }}</span>
          </div>
          <div class="price-item total">
            <span>总计</span>
            <span class="total-price">¥{{ totalPrice }}</span>
          </div>
        </div>

        <el-divider></el-divider>

        <div class="contact-info">
          <h3>联系人信息</h3>
          <el-form :model="form" :rules="rules" ref="form" label-width="80px">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号"></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
            </el-form-item>
          </el-form>
        </div>

        <div class="payment-method">
          <h3>支付方式</h3>
          <el-radio-group v-model="paymentMethod">
            <el-radio label="wechat">
              <i class="el-icon-money"></i>
              微信支付
            </el-radio>
            <el-radio label="alipay">
              <i class="el-icon-money"></i>
              支付宝
            </el-radio>
          </el-radio-group>
        </div>

        <div class="order-actions">
          <el-button @click="$router.go(-1)">返回</el-button>
          <el-button type="primary" @click="submitOrder" :loading="submitting">
            确认支付
          </el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: 'OrderConfirm',
  data() {
    return {
      movie: {
        id: 3,
        title: '流浪地球2',
        poster: require('@/assets/images/流浪地球2.webp'),
        rate: 9.4,
        director: '郭帆',
        stars: '吴京、刘德华、李雪健、沙溢、宁理、王智',
        type: '科幻/灾难',
        releaseDate: '2023-01-22',
        duration: 180,
        desc: '太阳急速衰老膨胀，短时间内将吞没包括地球在内的整个太阳系。为应对这一危机，人类集结全球之力，开启流浪地球计划：在地球表面建造万台行星发动机，推动地球离开太阳系，前往新家园。在这场跨越2500年的生存之旅中，人类不仅要面对极端环境挑战，更要应对人工智能MOSS带来的生存危机。本片聚焦行星发动机全面升级、太空电梯危机、月球发动机过载危机等震撼篇章，展现人类命运共同体的壮丽史诗。'
      },
      screening: {
        time: '2024-03-21 14:30',
        hall: '1号厅',
        price: 45
      },
      selectedSeats: ['A1', 'A2'],
      serviceFee: 5,
      form: {
        name: '',
        phone: '',
        email: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
        ]
      },
      paymentMethod: 'wechat',
      submitting: false
    }
  },
  computed: {
    totalPrice() {
      return this.screening.price * this.selectedSeats.length + this.serviceFee
    }
  },
  methods: {
    submitOrder() {
      this.$refs.form.validate(valid => {
        if (!valid) {
          return false
        }

        this.submitting = true
        // 模拟提交订单
        setTimeout(() => {
          this.submitting = false
          this.$message.success('支付成功！')
          this.$router.push('/')
        }, 2000)
      })
    }
  }
}
</script>

<style scoped>
.order-card {
  max-width: 800px;
  margin: 0 auto;
}

.movie-info {
  display: flex;
  margin-bottom: 20px;
}

.movie-poster {
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
}

.info-content {
  margin-left: 20px;
  flex: 1;
}

.info-content h2 {
  margin: 0 0 15px 0;
  font-size: 20px;
  color: #303133;
}

.info-content p {
  margin: 10px 0;
  color: #606266;
}

.seat-tag {
  margin-right: 5px;
}

.price-info {
  padding: 20px 0;
}

.price-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  color: #606266;
}

.price-item.total {
  font-size: 16px;
  color: #303133;
  font-weight: bold;
}

.total-price {
  color: #f56c6c;
  font-size: 20px;
}

.contact-info,
.payment-method {
  margin: 20px 0;
}

.contact-info h3,
.payment-method h3 {
  margin-bottom: 20px;
  font-size: 16px;
  color: #303133;
}

.payment-method .el-radio {
  margin-right: 30px;
}

.payment-method i {
  margin-right: 5px;
}

.order-actions {
  margin-top: 30px;
  text-align: right;
}

.order-actions .el-button {
  margin-left: 20px;
}
</style>